import aredis
import redis
import json


class MessageRedis(object):
    def __init__(self) -> None:
        self.async_redis = aredis.StrictRedis(host='localhost', port=6379, db=1, charset='UTF-8', encoding='UTF-8', decode_responses=True)
        self.redis = redis.StrictRedis(host='localhost', port=6379, db=1, charset='UTF-8', encoding='UTF-8', decode_responses=True)

    async def get_message(self, key):
        msg = await self.async_redis.get(key)
        return msg

    # 存储字典对象
    def set_message(self, key, msg):
        self.redis.set(key, json.dumps(msg))

    # 存储字典对象
    def set_string(self, key, value):
        self.redis.set(key, value)
